﻿using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using WebServerConnectorDll;

namespace FridgeManagerApp
{
    [DataContract]
    public class WPermission : NotificationObject
    {
        private String permissionUID;
        private String permissionName;
        private String describe;

        [DataMember(Order = 0)]
        public String PermissionUID
        {
            get
            {
                return permissionUID;
            }
            set
            {
                permissionUID = value;
                RaisePropertyChanged("PermissionUID");
            }
        }

        [DataMember(Order = 1)]
        public String PermissionName
        {
            get
            {
                return permissionName;
            }
            set
            {
                permissionName = value;
                RaisePropertyChanged("PermissionName");
            }
        }

        [DataMember(Order = 2)]
        public String Describe
        {
            get
            {
                return describe;
            }
            set
            {
                describe = value;
                RaisePropertyChanged("Describe");
            }
        }

        public WPermission()
        {
            PermissionUID = "";
            PermissionName = "";
            Describe = "";
        }

        public WPermission(LPermission p)
        {
            PermissionUID = p.PermissionUID;
            PermissionName = p.PermissionName;
            Describe = p.Describe;
        }

        public static List<WPermission> GetAll()
        {
            HttpResponse response = FridgeConnector.PostMessage(EStudy.Permission, EMethod.SelectAll, "");
            if (response.Status == "Success")
            {
                return JSON.parse<List<WPermission>>(response.Data1);
            }

            return null;
        }

        public static HttpResponse Insert(String pPostData)
        {
            return FridgeConnector.PostMessage(EStudy.Permission, EMethod.Insert, pPostData);
        }

        public static HttpResponse Update(String pPostData)
        {
            return FridgeConnector.PostMessage(EStudy.Permission, EMethod.Update, pPostData);
        }

        public static HttpResponse Delete(String pPostData)
        {
            return FridgeConnector.PostMessage(EStudy.Permission, EMethod.Delete, pPostData);
        }
    }
}
